package com.project.lk.nurseapp.remind;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.common.adapter.BaseRecycleViewAdapter;
import com.project.lk.nurseapp.db.RemindBean;
import com.suke.widget.SwitchButton;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class RemindAdapter extends BaseRecycleViewAdapter {
    List<RemindBean> mList = new ArrayList<>();
    Context mContext;

    public RemindAdapter(List<RemindBean> list, Context context) {
        this.mList = list;
        this.mContext = context;
    }

    public void setList(List<RemindBean> list){
        this.mList=list;
    }

    public List<RemindBean> getList(){
        return mList;
    }
    public interface OnItemEventListenter{
        void showClick(int positon,boolean isOpen);
    }

    OnItemEventListenter mListenter;
    public void setOnItemEventListenter(OnItemEventListenter listenter){
        this.mListenter=listenter;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_remind_layout, parent, false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.itemTime.setText(mList.get(position).getTime());
        viewHolder.itemContext.setText(mList.get(position).getRemindContext());
        viewHolder.itemDate.setText(mList.get(position).getDateStr());
        viewHolder.switchButton.setChecked(mList.get(position).getIsOpen());
        viewHolder.switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton switchButton, boolean isOpen) {
                mListenter.showClick(position,isOpen);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_time)
        TextView itemTime;
        @BindView(R.id.item_context)
        TextView itemContext;
        @BindView(R.id.item_date)
        TextView itemDate;
        @BindView(R.id.switch_button)
        SwitchButton switchButton;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
